import { defineStore } from 'pinia'
import apiList from '@/pages/login/api/api'
/**
 * 用户数据配置
 */

export const useUserStore = defineStore({
  id: 'user',
  state: () => ({
    userInfo: '',
    token: '',
    axiosCancelArr: []
  }),
  getters: {
    isLogin: state => {
      return state.token
    }
    /* CLEAR_CANCEL(state){
      state.axiosCancelArr.forEach(e=>{
        e && e()
      });
      state.axiosCancelArr = []
    } */
  },
  actions: {
    async handleLogout() {
      // const res = await apiList.logout()
      // if (res.code === 0) {
      this.token = ''
      ElMessage.success('退出登录成功！')
      return true
      // } else {
      //   return false
      // }
    },
    pushCancel(cancel) {
      this.axiosCancelArr.push(cancel.cancelToken)
    },
    clearCancel() {
      this.axiosCancelArr.forEach(e => {
        e && e()
      })
      this.axiosCancelArr = []
    }
  },
  // 持久化数据
  persist: {
    enabled: true
  }
})
